package com.ls.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ls.mapper.UserScoreMapper;
import com.ls.pojo.UserScore;
import com.ls.service.IUserScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaotang
 * @since 2023-04-07
 */
@Service
public class UserScoreServiceImpl extends ServiceImpl<UserScoreMapper, UserScore> implements IUserScoreService {

    @Resource
    private UserScoreMapper userScoreMapper;

    @Autowired
    private IUserScoreService userScoreService;
    @Override
    public Boolean addBuyscore(Integer userId, Integer addscore, Integer action) {
        //1、先查询出变动后最大的积分数
       Integer oldScore = userScoreMapper.findMaxOldScoreByUserId(userId);
       Integer newScore= oldScore+addscore;
        UserScore userScore = new UserScore();
        userScore.setUserId(userId);
        userScore.setNewScore(newScore);
        userScore.setOldScore(oldScore);
        userScore.setAction(action);

        int insert = userScoreMapper.insert(userScore);

        if (insert<=0){
            return false;
        }
        return true;
    }
}
